#ifndef		__OS_H_INCLUDED__
#define		__OS_H_INCLUDED__

#include	<string>
#include	<vector>

/**
 * High resolution date time format.
 */
struct DateTime {
	int year;
	int month;
	int day;
	int week;
	int hour;
	int minute;
	int second;
	int millisecond;
	int timestamp;
};

/**
 * Get next datetime after given milliseconds
 * 
 * \param start_time Start time
 * \param after Timespan in milliseconds
 * \return Next time
 */
extern DateTime operator+(const DateTime & start_time, double after);

/**
 * Get prev datetime before given milliseconds.
 * 
 * \param start_time Start time
 * \param before Timespan in milliseconds
 * \return Next time
 */
inline DateTime operator-(const DateTime & start_time, double before) { return start_time + (-before); }

/**
 * Calculate timespan between two datetime object.
 *
 * \param l Left value.
 * \param r Right value.
 * \return Timespan in milliseconds.
 */
extern double operator-(const DateTime & l, const DateTime & r);

/**
 * OS interfaces.
 */
struct OS {

	/**
	 * Dose given path(file or directory) exists?
	 *
	 * \param path Path for file or directory.
	 * \return True for given path exists. Otherwise false will be returned.
	 */
	static bool Exists(const std::string & path);

	/**
	 * Create directory.
	 *
	 * \param directory Path of directory to be created.
	 * \return Has this directory been created successfully?
	 */
	static bool CreateDir(const std::string & directory);

	/**
	 * Get current working directory.
	 */
	static std::string GetCWD();

	/**
	 * Set current working directory.
	 *
	 * \param directory Directory to be changed to.
	 * \return Operation result.
	 */
	static bool SetCWD(const std::string & directory);

	/**
	 * Get full path of a file/directory.
	 *
	 * \param path Path maybe relative to current workdir.
	 * \return Absolut full path of given file/directory.
	 */
	static std::string GetFullPath(const std::string & path);

	/**
	 * Get directory name of given file.
	 *
	 * \param file File path.
	 * \return Full directory name of given file.
	 */
	static std::string GetDirName(const std::string & file);

	/**
	 * Get file name with extension.
	 *
	 * \param file File path.
	 * \return File name with extension.
	 */
	static std::string GetFileName(const std::string & file);

	/**
	 * Get all files under given path.
	 *
	 * \param path Path to search start
	 * \param recursive Search into sub dirs?
	 * \return File lists.
	 */
	static std::vector<std::string> GetFiles(const std::string & path, bool recursive = true);

	/**
	 * Get current region timezone. [-12, 12]
	 */
	static int GetTimeZone();

	/**
	 * Get high resolution CPU clock time.
	 */
	static double Tick();

	/**
	 * Get high resolution date time.
	 */
	static DateTime Now();

	/**
	 * Parse data time
	 *
	 * \param year Year. [1970, --)
	 * \param month Month. [1, 12]
	 * \param day Day of month. [1, 31]
	 * \param hour 24-hours format. [0, 23]
	 * \param minute Minute. [0, 59]
	 * \param second Second. [0, 59]
	 * \return Parsed datatime.
	 */
	static DateTime ParseDateTime(int year, int month, int day, int hour, int minute, int second);

	/**
	 * Create platform dependent unique ID.
	 */
	static std::string CreateID();
};

#endif